package com.google.code.mergeinformer.model;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.UUID;

/**
 * @author Dmitry Golubev
 */
@MappedSuperclass
public abstract class DefaultEntity implements Serializable {

    @Id
    @Column(name = "id", unique = true, nullable = false)
    protected final String id = UUID.randomUUID().toString().replaceAll("-", "");

    public String getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(this.getClass().equals(o.getClass()))) {
            return false;
        }
        final DefaultEntity that = (DefaultEntity) o;
        return id.equals(that.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
